/*
 * @Description: 映射接口
 * @Author: Zzt
 * @Date: 2023-01-12 11:34:10
 * @LastEditTime: 2023-01-16 11:03:35
 */
import { IPageQuery } from '@/interfaces/global';
import request from '@/utils/request';

export interface IMappingParams {
  calssification?: number;
  id?: number;
  name?: string;
  remark?: string;
  sourceArchiveTypeId?: number;
  sourceFondsId?: number;
  targetArchiveTypeId?: number;
  targetFondsId?: number;
  templateMetadataMapRelations?: TemplateMetadataMapRelation[];
  type?: number;
}
export interface TemplateMetadataMapRelation {
  level?: number;
  mapFieldList?: MapFieldList[];
}
export interface MapFieldList {
  relation?: string;
  sortNo?: number;
  sourceFieldName?: string;
  sourceFieldOperator?: string;
  sourceFieldType?: number;
  targetFieldName?: string;
  targetFieldOperator?: string;
  targetFieldType?: number;
}
/* 新增 */
export function addMapping(data: IMappingParams) {
  return request({
    url: `/template-metadata-map/`,
    method: 'post',
    data
  });
}

/* 修改 */

export function editMapping(data: IMappingParams) {
  return request({
    url: `/template-metadata-map/`,
    method: 'put',
    data
  });
}

/* 分页查询 */
export interface fetchMappingListProps {
  calssification?: number;
  name?: string;
  sourceArchiveTypeId?: number;
  sourceFondsId?: number;
  targetArchiveTypeId?: number;
  targetFondsId?: number;
  type?: number;
}

export function fetchMappingByPage(data: IPageQuery<fetchMappingListProps>) {
  return request({
    url: `/template-metadata-map/page/`,
    method: 'post',
    data
  });
}

/* 删除 */
export function deleteMappingList(id: number | string) {
  return request({
    url: `/template-metadata-map/${id}`,
    method: 'delete'
  });
}
/* 下拉框查询列表 */
export function selectMappingList(data: fetchMappingListProps) {
  return request({
    url: `/template-metadata-map/select-list/`,
    method: 'post',
    data
  });
}
